package com.sgb.kjwl.view.ui.activity.enterprise;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPublishServiceCityShowBinding;
import com.sgb.kjwl.view.constant.RouterKey;
import com.swgk.core.recyclerview.entity.BaseAreaEntity;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;

/**
 * Time:2021/4/16
 * Author:黄淋
 * Description:发布的服务城市
 */
public class PublishServiceCityShowActivity extends AppActivity {
    ActivityPublishServiceCityShowBinding mBinding;


    private TagAdapter cityAdapter;
    private TagFlowLayout flowLayout;
    private ArrayList<BaseAreaEntity> choosenCityList;

    public static void start(Activity activity, ArrayList<BaseAreaEntity> list) {
        Intent intent = new Intent(activity, PublishServiceCityShowActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra(RouterKey.DATA, list);
        activity.startActivity(intent);
    }

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_publish_service_city_show);
        flowLayout = mBinding.getRoot().findViewById(R.id.city_list);
        initData();
    }


    private void initData() {
        if ((ArrayList<BaseAreaEntity>) getIntent().getSerializableExtra(RouterKey.DATA) != null) {
            choosenCityList = (ArrayList<BaseAreaEntity>) getIntent().getSerializableExtra(RouterKey.DATA);
        } else {
            choosenCityList = new ArrayList<>();
        }
        final LayoutInflater mInflater = LayoutInflater.from(PublishServiceCityShowActivity.this);
        cityAdapter = new TagAdapter<BaseAreaEntity>(choosenCityList) {
            @Override
            public View getView(com.zhy.view.flowlayout.FlowLayout parent, int position, BaseAreaEntity entity) {
                LinearLayout layout = (LinearLayout) mInflater.inflate(R.layout.item_service_city, flowLayout, false);
                TextView tv = layout.findViewById(R.id.tv_info);
                tv.setText(entity.getName());
                return layout;
            }
        };
        flowLayout.setAdapter(cityAdapter);
        cityAdapter.notifyDataChanged();
    }


}
